'use strict';
/**
 * @name 莫凡服务端 业务层
 * @version 0.0.1
 * @author xiech
 * @Time 2020年10月21日11:06:27
 */
const Service = require('egg').Service;
// 这个方法也映射到了全局   config.ctxutil = ctxutil;
const ctxutil = require('../../lib/mfinitctx.js');

// const operation_log = '[morefun:操作日志]';

class mfutilService extends Service {

  async test(ctx) {
    await ctxutil.apply(ctx);
    console.log(ctx);
    const result = {};

    // mongodb
    result.mongodbData = await ctx.mfutil.db.mongo.find('test', { name: '3333' }, { _id: -1 }, 0, 1);

    // mysql
    result.mysqldbData = await ctx.mfutil.db.mysql.query('SELECT 1 + 1 AS solution');

    // top接口 api 增加一个通用的post，get请求 httprequset
    result.topData = await ctx.mfutil.requset.taobaoTop.api('taobao.open.trades.sold.get', {
      fields: 'tid,type,status,payment,orders,rx_audit_status,buyer_nick',
      buyer_open_id: 'AAHRrFnxAJuoLN3qJ7N_tP7y',
    });
    return result;
  }

  async testPost(ctx) {
    await ctxutil.apply(ctx);
    console.log(ctx);
    const result = {};

    // mongodb
    result.mongodbData = await ctx.mfutil.db.mongo.find('test', { name: '3333' }, { _id: -1 }, 0, 1);

    // mysql
    result.mysqldbData = await ctx.mfutil.db.mysql.query('SELECT 1 + 1 AS solution');

    // top接口 api 增加一个通用的post，get请求 httprequset
    result.topData = await ctx.mfutil.requset.taobaoTop.api('taobao.open.trades.sold.get', {
      fields: 'tid,type,status,payment,orders,rx_audit_status,buyer_nick',
      buyer_open_id: 'AAHRrFnxAJuoLN3qJ7N_tP7y',
    });
    return result;
  }
}

module.exports = mfutilService;